local extension = Package:new("wq_hundun")
extension.extensionName = "FkWqmt"
Fk:loadTranslationTable{
  ["wq_hundun"] = "无期迷途·混沌",
}

local Wqc = require "packages/FkWqmt/wq_common"
local U = require "packages/utility/utility"

-- 禁闭者：诺克斯
local wq_nuokesi = General:new(extension, "wq_nuokesi", "qun", 4, 4, General.Female)
-- 技能：绝望
local wq_skill_juewang = fk.CreateTriggerSkill{
  name = "wq_skill_juewang",
  anim_type = "offensive",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Play
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, data, "#wq_skill_juewang_prompt")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:drawCards(player, 2, self.name)
    if not player:isNude() then
      local cid = room:askForDiscard(player, 1, 1, true, self.name, false)
      if cid then
        if Fk:getCardById(cid[1]).color == Card.Black then
          room:setPlayerMark(player, "wq_skill_juewang_mark", 1)
        end
      end
    end
  end,
  refresh_events = {fk.EventPhaseEnd},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Play and player:getMark("wq_skill_juewang_mark") > 0
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player, "wq_skill_juewang_mark", 0)
  end,
}
local wq_skill_juewang_buff = fk.CreateTargetModSkill{
  name = "#wq_skill_juewang_buff",
  bypass_distances =  function(self, player, skill)
    return skill.trueName == "slash_skill" and player:getMark("wq_skill_juewang_mark") > 0
  end,
  extra_target_func = function(self, player, skill)
    if skill.trueName == "slash_skill" and player:getMark("wq_skill_juewang_mark") > 0 then
      return 2
    end
  end,
}
wq_skill_juewang:addRelatedSkill(wq_skill_juewang_buff)
-- 技能：黑日
local wq_skill_heiri = fk.CreateTriggerSkill{
  name = "wq_skill_heiri",
  anim_type = "offensive",
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card.trueName == "slash" and data.card.color == Card.Black
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, data, "#wq_skill_heiri_prompt::"..data.to)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    data.card.skillName = self.name
    local to = room:getPlayerById(data.to)
    room:addPlayerMark(to, fk.MarkArmorNullified)
    data.extra_data = data.extra_data or {}
    data.extra_data.wq_skill_heiri_nullified = data.extra_data.wq_skill_heiri_nullified or {}
    data.extra_data.wq_skill_heiri_nullified[tostring(data.to)] = (data.extra_data.wq_skill_heiri_nullified[tostring(data.to)] or 0) + 1
  end,
  refresh_events = {fk.CardUseFinished, fk.Damage},
  can_refresh = function(self, event, target, player, data)
    if event == fk.CardUseFinished then
      return data.extra_data and data.extra_data.wq_skill_heiri_nullified
    elseif event == fk.Damage then
      return target == player and player:hasSkill(self) and data.card and data.card.skillName == self.name
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if event == fk.CardUseFinished then
      for key, num in pairs(data.extra_data.wq_skill_heiri_nullified) do
        local p = room:getPlayerById(tonumber(key))
        if p:getMark(fk.MarkArmorNullified) > 0 then
          room:removePlayerMark(p, fk.MarkArmorNullified, num)
        end
      end
      data.wq_skill_heiri_nullified = nil
    elseif event == fk.Damage then
      room:changeShield(player, 1)
    end
  end,
}
-- 技能：灰败
local wq_skill_huibai = fk.CreateTriggerSkill{
  name = "wq_skill_huibai",
  anim_type = "special",
  frequency = Skill.Compulsory,
  events = {fk.Death},
  can_trigger = function(self, event, target, player, data)
    return target ~= player and player:isAlive() and player:hasSkill(self.name)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:addPlayerMark(player, "wq_skill_huibai_mark", 1)
  end,
}
local wq_skill_huibai_maxcard = fk.CreateMaxCardsSkill{
  name = "#wq_skill_huibai_maxcard",
  correct_func = function(self, player)
    return player:hasSkill(self) and player:getMark("wq_skill_huibai_mark") or 0
  end,
}
wq_skill_huibai:addRelatedSkill(wq_skill_huibai_maxcard)
-- 诺克斯技能
wq_nuokesi:addSkill(wq_skill_juewang)
wq_nuokesi:addSkill(wq_skill_heiri)
wq_nuokesi:addSkill(wq_skill_huibai)
-- 诺克斯翻译
Fk:loadTranslationTable{
  ["wq_nuokesi"] = "诺克斯",
  ["#wq_nuokesi"] = "生命转化",
  ["designer:wq_nuokesi"] = "妙霄",
  ["cv:wq_nuokesi"] = "官方",
  ["illustrator:wq_nuokesi"] = "官方",
  ["wq_skill_juewang"] = "绝望",
  [":wq_skill_juewang"] = "出牌阶段开始时，你可以摸两张牌，并弃置一张牌。若你以此法弃置了黑色牌，此阶段内你使用【杀】无距离限制且可以多指定两个目标。",
  ["$wq_skill_juewang"] = "死亡才是你们的归宿！",
  ["#wq_skill_juewang_prompt"] = "绝望：你可以摸两张牌，并弃置一张牌<br>若你以此法弃置了黑色牌，此阶段内你使用【杀】无距离限制且可以多指定两个目标",
  ["wq_skill_heiri"] = "黑日",
  [":wq_skill_heiri"] = "当你使用黑色【杀】指定目标后，你可以令此【杀】无视其防具。若如此做，此【杀】每次造成伤害后，你获得1点护甲。",
  ["$wq_skill_heiri"] = "我听到深渊的呼唤……",
  ["#wq_skill_heiri_prompt"] = "黑日：你可以令此【杀】无视%dest的防具，且此【杀】每次造成伤害后你获得1点护甲",
  ["wq_skill_huibai"] = "灰败",
  [":wq_skill_huibai"] = "锁定技，当一名角色死亡时，你的手牌上限+1。",
  ["$wq_skill_huibai"] = "这把剑沾染过的血……我永远不会忘记。",
  ["~wq_nuokesi"] = "我……不想……死……",
}

-- 禁闭者：曜
local wq_yao = General:new(extension, "wq_yao", "qun", 4, 4, General.Female)
-- 技能：灾祭
local wq_skill_zaiji = fk.CreateActiveSkill{
  name = "wq_skill_zaiji",
  anim_type = "control",
  prompt = function (self, selected, selected_cards)
    return "#wq_skill_zaiji_prompt-invoke"
  end,
  can_use = function (self, player)
    return #player:getAvailableEquipSlots() > 0 and player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  target_num = 0,
  card_num = 0,
  card_filter = Util.FalseFunc,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local player_choices = player:getAvailableEquipSlots()
    local player_choice = room:askForChoice(player, player_choices, self.name)
    room:abortPlayerArea(player, player_choice)
    if not player:isAlive() then return end
    local tids = room:askForChoosePlayers(player, table.map(room:getOtherPlayers(player), function (p) return p.id end), 1, 1, "#wq_skill_zaiji_prompt-target", self.name, false)
    local target = room:getPlayerById(tids[1])
    local target_choices = {}
    table.insert(target_choices, "#wq_skill_zaiji_choice-giveCard:"..player.id.."::"..math.min(5, target.maxHp))
    table.insert(target_choices, "#wq_skill_zaiji_choice-notGive:"..player.id)
    local target_choice = room:askForChoice(target, target_choices, self.name)
    if target_choice:startsWith("#wq_skill_zaiji_choice-giveCard") then
      room:loseHp(target, 1, self.name)
      if target:isAlive() and player:isAlive() and (not target:isKongcheng()) then
        local dummy = Fk:cloneCard("dilu")
        dummy:addSubcards(target:getCardIds("h"))
        room:obtainCard(player.id, dummy, false, fk.ReasonGive, target.id)
        if target:isAlive() then
          room:drawCards(target, math.min(5, target.maxHp), self.name)
        end
      end
    else
      room:loseHp(player, 1, self.name)
    end
  end,
}
-- 技能：金乌
local wq_skill_jinwu = fk.CreateTriggerSkill{
  name = "wq_skill_jinwu",
  anim_type = "special",
  events = {fk.DamageCaused},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and player == target and player:getHandcardNum() >= player.hp
  end,
  on_use = function(self, event, target, player, data)
    data.damageType = fk.FireDamage
  end,
  refresh_events = {fk.Damaged},
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(self) and player == data.from and player ~= target and player:getHandcardNum() >= player.hp
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    room:addPlayerMark(target, "@wq_mark_ranshao", 1)
  end,
}
local wq_skill_jinwu_targetmod = fk.CreateTargetModSkill{
  name = "#wq_skill_jinwu_targetmod",
  residue_func = function(self, player, skill, scope)
    if player:hasSkill("wq_skill_jinwu") and skill.trueName == "slash_skill" and player:getHandcardNum() >= player.hp and scope == Player.HistoryPhase then
      return 999
    end
  end,
  distance_limit_func =  function(self, player, skill)
    if player:hasSkill("wq_skill_jinwu") and skill.trueName == "slash_skill" and player:getHandcardNum() >= player.hp then
      return 999
    end
  end,
}
wq_skill_jinwu:addRelatedSkill(wq_skill_jinwu_targetmod)
-- 技能：照临
local wq_skill_zhaolin = fk.CreateTriggerSkill{
  name = "wq_skill_zhaolin",
  anim_type = "offensive",
  events = {fk.DamageInflicted},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target ~= player and data.skillName == "#wq_common_mark_ranshao_damage"
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    return room:askForSkillInvoke(player, self.name, data, "#wq_skill_zhaolin_prompt::"..target.id)
  end,
  on_use = function(self, event, target, player, data)
    data.damage = data.damage + 1
  end,
}
-- 曜的技能
wq_yao:addSkill(wq_skill_zaiji)
wq_yao:addSkill(wq_skill_jinwu)
wq_yao:addSkill(wq_skill_zhaolin)
-- 曜的翻译
Fk:loadTranslationTable{
  ["wq_yao"] = "曜",
  ["#wq_yao"] = "焚天之焰",
  ["designer:wq_yao"] = "妙霄",
  ["cv:wq_yao"] = "官方",
  ["illustrator:wq_yao"] = "官方",
  ["wq_skill_zaiji"] = "灾祭",
  [":wq_skill_zaiji"] = "出牌阶段限一次，你可以废除一个装备栏，并指定一名其他角色。该角色需选择一项：1.失去1点体力，令你获得其所有手牌，然后其摸X张牌（X为其体力上限且至多为5）；2.令你失去1点体力。",
  ["$wq_skill_zaiji"] = "天照流火！",
  ["#wq_skill_zaiji_prompt-invoke"] = "灾祭：你可以废除一个装备栏并指定一名其他角色，其需选择一项：<br>1.失去1点体力，令你获得其所有手牌，然后其摸X张牌（X为其体力上限且至多为5）<br>2.令你失去1点体力",
  ["#wq_skill_zaiji_prompt-target"] = "灾祭：请选择一名其他角色",
  ["#wq_skill_zaiji_choice-giveCard"] = "失去1点体力，令%src获得你的所有手牌，然后你摸%arg张牌",
  ["#wq_skill_zaiji_choice-notGive"] = "令%src失去1点体力",
  ["wq_skill_jinwu"] = "金乌",
  [":wq_skill_jinwu"] = "锁定技，出牌阶段，若你的手牌数不小于体力值，则：你使用【杀】无距离和次数限制；你造成的伤害均视为火焰伤害；其他角色受到你造成的伤害后获得1枚「燃烧」标记。"
  ..Wqc.getTranslateInNewLine("#wq_common_mark_ranshao_description"),
  ["$wq_skill_jinwu"] = "焚为灰烬吧！",
  ["wq_skill_zhaolin"] = "照临",
  [":wq_skill_zhaolin"] = "当其他角色因“燃烧判定”而受到伤害时，你可以令此伤害+1。",
  ["$wq_skill_zhaolin"] = "太阳的华光，不容遮蔽！",
  ["#wq_skill_zhaolin_prompt"] = "照临：你可以令%dest此次受到的火焰伤害+1",
  ["~wq_yao"] = "这本就是……灾厄之命……",
}

-- 禁闭者：科希
local wq_kexi = General:new(extension, "wq_kexi", "qun", 3, 3, General.Female)
-- 技能：影匿
local wq_skill_yingni = fk.CreateActiveSkill{
  name = "wq_skill_yingni",
  anim_type = "special",
  card_num = 0,
  target_num = 0,
  prompt = function (self, selected, selected_cards)
    return "#wq_skill_yingni_prompt"
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    player:turnOver()
  end,
}
local wq_skill_yingni_damaged = fk.CreateTriggerSkill{
  name = "#wq_skill_yingni_damaged",
  events = {fk.Damaged},
  frequency = Skill.Compulsory,
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill("wq_skill_yingni") and (not player.faceup)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke("wq_skill_yingni")
    room:notifySkillInvoked(player, "wq_skill_yingni", "masochism")
    player:turnOver()
  end,
}
local wq_skill_yingni_prohibit = fk.CreateProhibitSkill{
  name = "#wq_skill_yingni_prohibit",
  frequency = Skill.Compulsory,
  is_prohibited = function(self, from, to, card)
    if to:hasSkill("wq_skill_yingni") and (not to.faceup) then
      return card.trueName == "slash"
    end
  end,
}
wq_skill_yingni:addRelatedSkill(wq_skill_yingni_damaged)
wq_skill_yingni:addRelatedSkill(wq_skill_yingni_prohibit)
-- 技能：狂袭
local wq_skill_kuangxi = fk.CreateTriggerSkill{
  name = "wq_skill_kuangxi",
  anim_type = "offensive",
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    local room = player.room
    return target == player and player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryTurn) == 0 and (not player.faceup) and data.card.trueName == "slash" and data.card.color == Card.Black and (not room:getPlayerById(data.to):isNude())
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, data, "#wq_skill_kuangxi_prompt::"..data.to)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local dest = room:getPlayerById(data.to)
    if not dest:isNude() then
      local cid = room:askForCardsChosen(player, dest, 1, 1, "he", self.name)
      room:throwCard(cid, self.name, dest, player)
    end
    if player:isAlive() and dest:isAlive() then
      room:damage{
        from = player,
        to = dest,
        damage = 1,
        skillName = self.name,
      }
    end
  end,
}
-- 技能：化影
local wq_skill_huaying = fk.CreateTriggerSkill{
  name = "wq_skill_huaying",
  anim_type = "special",
  events = {fk.TurnedOver, fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    if event == fk.TurnedOver then
      return target == player and player:hasSkill(self)
    elseif event == fk.TargetSpecified then
      return target == player and player:hasSkill(self) and (data.card.type == Card.TypeBasic or data.card:isCommonTrick()) and #AimGroup:getAllTargets(data.tos) == 1 and (not player:isKongcheng())
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TurnedOver then
      return room:askForSkillInvoke(player, self.name, data, "#wq_skill_huaying_prompt-turnedOver")
    elseif event == fk.TargetSpecified then
      local cids = room:askForCard(player, 1, 1, false, self.name, true, ".|.|spade,club|hand", "#wq_skill_huaying_prompt-effect:::"..data.card:toLogString())
      if #cids > 0 then
        self.cost_data = cids
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TurnedOver then
      local cids = room:getNCards(2, "bottom")
      room:moveCardTo(cids, Card.Processing, nil, fk.ReasonJustMove, self.name)
      local cards = {}
      for _, id in ipairs(cids) do
        local card = Fk:getCardById(id)
        if card.color == Card.Black then
          table.insert(cards, id)
        end
      end
      if #cards > 0 then
        local dummy = Fk:cloneCard("slash")
        dummy:addSubcards(cards)
        room:obtainCard(player, dummy, true, fk.ReasonJustMove, player.id)
      end
      cids = table.filter(cids, function(id) return room:getCardArea(id) == Card.Processing end)
      room:moveCardTo(cids, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, self.name, nil, true, player.id)
    elseif event == fk.TargetSpecified then
      local cids = self.cost_data
      if #cids > 0 then
        local num = 0
        for _, id in ipairs(cids) do
          local card = Fk:getCardById(id)
          if card.color == Card.Black then
            num = num + 1
          end
        end
        num = math.min(1, num)
        room:recastCard(cids, player, self.name)
        if num > 0 then
          data.additionalEffect = num
        end
      end
    end
  end,
}
-- 科希的技能
wq_kexi:addSkill(wq_skill_yingni)
wq_kexi:addSkill(wq_skill_kuangxi)
wq_kexi:addSkill(wq_skill_huaying)
-- 科希的翻译
Fk:loadTranslationTable{
  ["wq_kexi"] = "科希",
  ["#wq_kexi"] = "阴影隐匿",
  ["designer:wq_kexi"] = "妙霄",
  ["cv:wq_kexi"] = "官方",
  ["illustrator:wq_kexi"] = "官方",
  ["wq_skill_yingni"] = "影匿",
  [":wq_skill_yingni"] = "出牌阶段限一次，你可以翻面。锁定技，若你的武将牌背面向上，你不能成为【杀】的目标；当你受到伤害后，若你的武将牌背面向上，你将其翻回正面。",
  ["$wq_skill_yingni"] = "情况有些变化。",
  ["#wq_skill_yingni_prompt"] = "影匿：你可以翻面",
  ["#wq_skill_yingni_damaged"] = "影匿",
  ["wq_skill_kuangxi"] = "狂袭",
  [":wq_skill_kuangxi"] = "每回合限一次，当你使用黑色【杀】指定目标后，若你的武将牌背面向上，你可以弃置其一张牌，然后对其造成1点伤害。",
  ["$wq_skill_kuangxi"] = "非要我上场的话，就快点结束战斗。",
  ["#wq_skill_kuangxi_prompt"] = "狂袭：你可以弃置%dest一张牌，然后对其造成1点伤害",
  ["wq_skill_huaying"] = "化影",
  [":wq_skill_huaying"] = "当你翻面时，你可以亮出牌堆底的两张牌，并获得其中的黑色牌。当你使用基本牌或普通锦囊牌指定唯一目标后，你可以重铸一张黑色手牌，令此牌额外结算一次。",
  ["$wq_skill_huaying"] = "如影……随形。",
  ["#wq_skill_huaying_prompt-turnedOver"] = "化影：你可以亮出牌堆底的两张牌，并获得其中的黑色牌",
  ["#wq_skill_huaying_prompt-effect"] = "化影：你可以重铸一张黑色手牌，令%arg额外结算一次",
  ["~wq_kexi"] = "好黑……好冷啊……",
}

-- 禁闭者：可可莉克
local wq_kekelike = General:new(extension, "wq_kekelike", "qun", 3, 3, General.Female)
-- 技能：绯花
local wq_skill_feihua = fk.CreateActiveSkill{
  name = "wq_skill_feihua",
  anim_type = "support",
  card_num = 0,
  target_num = 0,
  prompt = function (self, selected, selected_cards)
    return "#wq_skill_feihua_prompt-invoke"
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local cids = room:getNCards(3)
    room:moveCardTo(cids, Card.Processing, nil, fk.ReasonJustMove, self.name)
    local cards = {}
    for _, id in ipairs(cids) do
      local card = Fk:getCardById(id)
      if card.color == Card.Red then
        table.insert(cards, id)
      end
    end
    local tids = room:askForChoosePlayers(player, table.map(room:getAlivePlayers(), Util.IdMapper), 1, 1, "#wq_skill_feihua_prompt-choose", self.name, false)
    if #tids > 0 then
      local dest = room:getPlayerById(tids[1])
      room:setPlayerMark(dest, "wq_skill_feihua_mark_invoked", 1)
      room:setPlayerMark(dest, "wq_skill_feihua_mark_dest_"..player.id, 1)
      if #cards > 0 then
        local dummy = Fk:cloneCard("slash")
        dummy:addSubcards(cards)
        room:obtainCard(dest, dummy, true, fk.ReasonJustMove, player.id)
      end
    end
    cids = table.filter(cids, function(id) return room:getCardArea(id) == Card.Processing end)
    room:moveCardTo(cids, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, self.name, nil, true, player.id)
  end,
}
local wq_skill_feihua_buff = fk.CreateTriggerSkill{
  name = "#wq_skill_feihua_buff",
  mute = true,
  refresh_events = {fk.HpLost, fk.EventPhaseStart},
  can_refresh = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventPhaseStart then
      return player.id == target.id and player:hasSkill(self) and player.phase == Player.Start
    else
      return player:hasSkill(self) and #table.filter(room:getAlivePlayers(), function(p) return p:getMark("wq_skill_feihua_mark_dest_"..player.id) > 0 and p:isWounded() end) > 0
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventPhaseStart then
      table.forEach(room:getAlivePlayers(), function(p)
        room:setPlayerMark(p, "wq_skill_feihua_mark_dest_"..player.id, 0)
      end)
    else
      player:broadcastSkillInvoke("wq_skill_feihua")
      room:notifySkillInvoked(player, "wq_skill_feihua")
      table.forEach(room:getAlivePlayers(), function(p)
        if p:getMark("wq_skill_feihua_mark_dest_"..player.id) > 0 and p:isWounded() then
          room:recover {
            who = p,
            num = 1,
            recoverBy = player,
            skillName = "wq_skill_feihua"
          }
        end
      end)
    end
  end,
}
wq_skill_feihua:addRelatedSkill(wq_skill_feihua_buff)
-- 技能：剑落
local wq_skill_jianluo = fk.CreateTriggerSkill{
  name = "wq_skill_jianluo",
  anim_type = "offensive",
  events = {fk.EventPhaseStart, fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventPhaseStart then
      return target == player and player:hasSkill(self) and player.phase == Player.Finish and not player:prohibitUse(Fk:cloneCard("slash"))
    elseif event == fk.Damaged then
      return player:hasSkill(self) and player:getMark("wq_skill_jianluo_mark_invoked") == 0 
      and data.to and data.to:isAlive() and data.to.id ~= player.id 
      and #table.filter(room:getAlivePlayers(), function(p) return p:getMark("wq_skill_feihua_mark_invoked") > 0 end) > 0 
      and data.card and data.card.trueName == "slash"
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventPhaseStart then
      local slash = Fk:cloneCard("slash")
      local max_num = slash.skill:getMaxTargetNum(player, slash)
      local targets = {}
      for _, p in ipairs(room:getOtherPlayers(player)) do
        if (not player:isProhibited(p, slash)) and player:inMyAttackRange(p) then
          table.insert(targets, p.id)
        end
      end
      if #targets == 0 or max_num == 0 then return end
      local tos = room:askForChoosePlayers(player, targets, 1, max_num, "#wq_skill_jianluo_prompt-finish", self.name, true)
      if #tos > 0 then
        self.cost_data = tos
        return true
      end
    elseif event == fk.Damaged then
      local num = #table.filter(room:getAlivePlayers(), function(p) return p:getMark("wq_skill_feihua_mark_invoked") > 0 end)
      self.cost_data = num
      return room:askForSkillInvoke(player, self.name, data, "#wq_skill_jianluo_prompt-damaged::"..data.to.id..":"..num)
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventPhaseStart then
      local slash = Fk:cloneCard("slash")
      slash.skillName = self.name
      room:useCard {
        from = target.id,
        tos = table.map(self.cost_data, function(pid) return { pid } end),
        card = slash,
        extraUse = true,
      }
    elseif event == fk.Damaged then
      room:setPlayerMark(player, "wq_skill_jianluo_mark_invoked", 1)
      local num = self.cost_data
      local dest = data.to
      for i = 1, num, 1 do
        local slash = Fk:cloneCard("slash")
        slash.skillName = self.name
        if U.canUseCardTo(room, dest, player, slash) then
          room:useCard{
            from = player.id,
            tos = {{dest.id}},
            card = slash,
            extraUse = true,
          }
        else
          break
        end
        if player.dead or dest.dead then break end
      end
    end
  end,
  refresh_events = {fk.CardUseFinished, fk.RoundEnd},
  can_refresh = function(self, event, target, player, data)
    if event == fk.CardUseFinished then
      return data.extra_data and data.extra_data.wq_skill_jianluo_nullified
    elseif event == fk.RoundEnd then
      return player:hasSkill(self)
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if event == fk.CardUseFinished then
      for key, num in pairs(data.extra_data.wq_skill_jianluo_nullified) do
        local p = room:getPlayerById(tonumber(key))
        if p:getMark(fk.MarkArmorNullified) > 0 then
          room:removePlayerMark(p, fk.MarkArmorNullified, num)
        end
      end
      data.wq_skill_jianluo_nullified = nil
    elseif event == fk.RoundEnd then
      room:setPlayerMark(player, "wq_skill_jianluo_mark_invoked", 0)
    end
  end,
}
local wq_skill_jianluo_buff = fk.CreateTriggerSkill{
  name = "#wq_skill_jianluo_buff",
  mute = true,
  frequency = Skill.Compulsory,
  events = {fk.TargetSpecified, fk.PreDamage},
  can_trigger = function(self, event, target, player, data)
    if event == fk.TargetSpecified then
      return target.id == player.id and player:hasSkill(self) and data.card.trueName == "slash"
    elseif event == fk.PreDamage then
      return target.id == player.id and player:hasSkill(self) and data.card and data.card.trueName == "slash"
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TargetSpecified then
      player:broadcastSkillInvoke("wq_skill_jianluo")
      room:notifySkillInvoked(player, "wq_skill_jianluo")
      data.card.skillName = self.name
      local to = room:getPlayerById(data.to)
      room:addPlayerMark(to, fk.MarkArmorNullified)
      data.extra_data = data.extra_data or {}
      data.extra_data.wq_skill_jianluo_nullified = data.extra_data.wq_skill_jianluo_nullified or {}
      data.extra_data.wq_skill_jianluo_nullified[tostring(data.to)] = (data.extra_data.wq_skill_jianluo_nullified[tostring(data.to)] or 0) + 1
    elseif event == fk.PreDamage then
      room:loseHp(data.to, data.damage, self.name)
      return true
    end
  end,
}
wq_skill_jianluo:addRelatedSkill(wq_skill_jianluo_buff)
-- 可可莉克的技能
wq_kekelike:addSkill(wq_skill_feihua)
wq_kekelike:addSkill(wq_skill_jianluo)
-- 可可莉克的翻译
Fk:loadTranslationTable{
  ["wq_kekelike"] = "可可莉克",
  ["#wq_kekelike"] = "绯花剑落",
  ["designer:wq_kekelike"] = "妙霄",
  ["cv:wq_kekelike"] = "官方",
  ["illustrator:wq_kekelike"] = "官方",
  ["wq_skill_feihua"] = "绯花",
  [":wq_skill_feihua"] = "出牌阶段限一次，你可以亮出牌堆顶三张牌，然后指定一名角色。该角色获得其中的所有红色牌，且直到你的下一个准备阶段，每当一名角色失去体力后，该角色回复1点体力。",
  ["$wq_skill_feihua"] = "于此绽放，直至荼蘼。",
  ["#wq_skill_feihua_prompt-invoke"] = "绯花：你可以亮出牌堆顶三张牌，然后指定一名角色，该角色获得其中的所有红色牌<br>且直到你的下一个准备阶段，每当一名角色失去体力后，该角色回复1点体力",
  ["#wq_skill_feihua_prompt-choose"] = "绯花：请选择一名角色，令其获得其中的所有红色牌",
  ["wq_skill_jianluo"] = "剑落",
  [":wq_skill_jianluo"] = "结束阶段，你可以视为使用一张【杀】。每轮限一次，其他角色受到【杀】的伤害后，你可以视为对其使用X张【杀】（X为场上成为过【绯花】目标的存活角色数）。锁定技，你使用的【杀】无视目标的防具且造成的伤害均视为体力流失。",
  ["$wq_skill_jianluo"] = "我所到之处，将遍地盛开鲜花。",
  ["#wq_skill_jianluo_prompt-finish"] = "剑落：你可以视为使用一张【杀】",
  ["#wq_skill_jianluo_prompt-damaged"] = "剑落：你可以视为对%dest使用%arg张【杀】",
  ["#wq_skill_jianluo_buff"] = "剑落",
  ["~wq_kekelike"] = "这将是……最美的花雨……",
}

return extension